import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
Vue.use(Router)

var router = new Router({
  mode: "history",
  routes: [
    {
      path: '/HelloWorld',
      name: 'HelloWorld',
      component: HelloWorld
    }, {
      path: '/Classify',
      name: 'Classify',
      component: () => import("@/components/Classify"),
      children: [{
        path: '/Classify',
        component: () => import("@/components/Navdetail"),
      },{path: '/navdetail/:id',
      component: () => import("@/components/Navdetail"),
    }]
    }, {
      path: '/My',
      name: 'My',
      component: () => import("@/components/My")
    }, {
      path: '/Shopping',
      name: 'Shopping',
      component: () => import("@/components/Shopping")
    }, {
      path: '/Detail',
      name: 'Detail',
      component: () => import("@/components/Detail")
    }, {
      path: '/Register',
      name: 'Register',
      component: () => import("@/components/Register")
    }, {
      path: '/Login',
      name: 'Login',
      component: () => import("@/components/Login")
    }, {
      path: '/byCode',
      name: 'byCode',
      component: () => import("@/components/byCode")
    }, {
      path: '/Amend',
      name: 'Amend',
      component: () => import("@/components/Amend")
    }, {
      path: '/mdetail',
      name: 'MusicDetail',
      component: () => import("@/components/MusicDetail")
    }, {
      path: '/search',
      name: 'Search',
      component: () => import("@/components/Search")
    }

  ]
});
// 全局路由守卫
router.beforeEach((to, from, next) => {
  if (to.path == "/Login" || to.path == "/Register" || to.path == "/byCode") {
    next();
  } else {
    if (sessionStorage.getItem("token")) {
      next();
    } else {
      next("/Login");
    }
  }
})

export default router;
